package com.qing.eduservice.controller;

import com.qing.eduservice.entity.dto.EduTeacherDto;
import com.qing.eduservice.entity.pojo.EduTeacher;
import com.qing.eduservice.entity.vo.EduTeacherVo;
import com.qing.eduservice.service.EduTeacherService;
import com.qing.servicebase.utils.ResponseResult;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 * 讲师 前端控制器
 * </p>
 *
 * @author Yjx
 * @since 2022-09-06
 */
@RestController
@RequestMapping("/eduservice/teacher")
public class EduTeacherController {

    private final EduTeacherService eduTeacherService;

    public EduTeacherController(EduTeacherService eduTeacherService) {
        this.eduTeacherService = eduTeacherService;
    }

    /**
     * 查询所有老师
     *
     * @return
     */
    @GetMapping(value = "/finall")
    public ResponseResult fineAllTeacher() {
        return eduTeacherService.queryAllTeacher();
    }

    /**
     * 根据id删除老师
     *
     * @param
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public ResponseResult removeById(@PathVariable("id") String id) {
        return eduTeacherService.deleteTeacherById(id);
    }

    /**
     * 根据id查询教师
     *
     * @param
     * @return
     */
    @GetMapping("/search/{id}")
    public ResponseResult searchTeacherById(@PathVariable("id") String id) {
        return eduTeacherService.searchTeacherById(id);
    }


    /**
     * 增加教师
     *
     * @param eduTeacher
     * @return
     */
    @PostMapping(value = "/create")
    public ResponseResult createTeacher(@RequestBody EduTeacher eduTeacher) {
        return eduTeacherService.createTeacher(eduTeacher);
    }

    /**
     * 修改教师信息
     *
     * @param eduTeacher
     * @return
     */
    @PutMapping(value = "/update")
    public ResponseResult updateTeacherById(@RequestBody EduTeacher eduTeacher) {
        System.out.println(eduTeacher);
        return eduTeacherService.updateTeacherById(eduTeacher);
    }

    @PostMapping(value = "/page/{page}/{pageSize}")
    public ResponseResult queryTeacherBypage(
            @PathVariable int page,
            @PathVariable int pageSize,
            @RequestBody EduTeacherVo eduTeacherVo
    ) {
        return eduTeacherService.queryBookByPage(page, pageSize, eduTeacherVo);
    }
}

